import Data from '../data/data';
import * as Api from '@/api/configCenter/configCenter';
import type * as ApiType from "@/api/configCenter/configCenter.d";
type ApiEnum<T, K extends keyof T> = {[P in K]: T[P];}
interface Prop {
  PageDataHooks: MarkPage.PageDataHooks;
}
/**
 * 配置中心除标签配置外的其他页面列表查询辅助方法
 * @param type 当前页面的类型数值
 * @param params 请求当前页面的列表数据参数
 * @returns 放回当前列表数据
 */
export const getTableData = async (type: number, params: ApiType.GetLesionParams | ApiType.GetCompDataParams | ApiType.GetToolDataParams) => {
  if (type === 0 || type === 4) return;
  const ApiEnum: ApiEnum<any, number> = {
    1: Api.getLesionData,
    2: Api.getCompData,
    3: Api.getToolData,
  }
  const result = await ApiEnum[type](params)
  return result;
}

/**
 * 获取配置中心除标签配置外的其他页面的查询表单，列表，页面元素等辅助方法
 * @param routerPath 当前页面路由路径
 * @returns 当前页面的基础数据参数
 */
export const getBaseData = (routerPath: string) => {
  const pathEnum: ApiEnum<any, string> = {
    "/configCenter/labeltype": {
      searchPlaceholder: "标注类型",
      pageTitle: "标注类型列表",
      columns: Data.typeColumns,
      searchForm: {
        name: undefined,
        page: 1,
        pageSize: 10
      },
      pageType: 1
    },
    "/configCenter/labelcomponent": {
      searchPlaceholder: "组件名称",
      pageTitle: "标注组件列表",
      columns: Data.compColumns,
      searchForm: {
        name: undefined,
        page: 1,
        pageSize: 10
      },
      pageType: 2
    },
    "/configCenter/labeltool": {
      searchPlaceholder: "标注工具",
      pageTitle: "标注工具列表",
      columns: Data.toolColumns,
      searchForm: {
        name: undefined,
        page: 1,
        pageSize: 10
      },
      pageType: 3
    },
    "/configCenter/labelconfig": {
      isLeftContainer: true,
      pageField: "name",
      placeholder: "标签",
      field: 'name',
      paginationProps: {
        defaultPageSize: 20,
        total: 0,
      },
      labelModel: {
        parentId: 0,
        page: 1,
        pageSize: 10
      },
      pageType: 4
    }
  }
  return pathEnum[routerPath];
}

/**
 * 标签配置的子项列表表头获取辅助方法
 * @param id 标签配置当前标签的id值
 * @returns 返回当前标签配置的子项列表表头数据
 */
export const getLabelItemColumns = (id: number) => {
  let result;
  switch (id) {
    case 6:
      result = Data.labelChildColumns.map((item, index) => {
        let tempObj = item;
        if (index === Data.labelChildColumns.length - 1) {
          tempObj = {
            title: '窗位*窗宽',
            dataIndex: 'value',
            ellipsis: true,
            tooltip: true
          }
        }
        return tempObj;
      })
      result.push(Data.labelChildColumns[Data.labelChildColumns.length - 1]);
      break;
    case 7:
      result = Data.labelChildColumns.map((item, index) => {
        let tempObj = item;
        if (index === Data.labelChildColumns.length - 1) {
          tempObj = {
            title: '版本',
            dataIndex: 'value',
            ellipsis: true,
            tooltip: true
          }
        }
        return tempObj;
      })
      result.push(Data.labelChildColumns[Data.labelChildColumns.length - 1]);
      break;
    default:
      result = Data.labelChildColumns;
      break;
  }
  return result;
}

/**
 * 标签配置的子项查询表单，列表，页面元素等辅助方法
 * @param item 当前标签配置的点击项
 * @returns 返回当前标签配置的子项页面基本数据
 */
export const getLabelItemBase = (item: ApiType.LabelListItem) => {
  const result: ApiEnum<any, string> = {
    pageTitle: item.name + '列表',
    field: 'name',
    pageField: 'name',
    searchPlaceholder: item.name + '名称',
  }
  const labelModel: ApiEnum<any, string> = {
    name: undefined,
    parentId: item.id,
    page: 1,
    pageSize: 10
  }
  const resultEnum: ApiEnum<any, string> = {
    1: {
      result,
      labelModel
    },
    2: {
      result,
      labelModel
    },
    3: {
      result,
      labelModel
    },
    4: {
      result,
      labelModel
    },
    5: { // 废片原因
      result: {
        ...result,
        pageTitle: item.name,
        searchPlaceholder: item.name
      },
      labelModel
    },
    6: { // 窗宽窗位
      result : {
        ...result,
        searchPlaceholder: '名称'
      },
      labelModel
    },
    7: { // 算法版本
      result: {
        ...result,
        searchPlaceholder: '名称/版本'
      },
      labelModel
    }
  }
  return resultEnum[item.id];
}

export const viewMode = {
  CREATE: 'create',
  EDIT: 'edit',
  VIEW: 'view',
}

export const getModelBase = (type: number, modelType: string, data?: any) => {
  let baseData: ApiEnum<any, string> = {};
  let modelForm: ApiEnum<any, string> = {};
  if (type === 1 && modelType === viewMode.CREATE) {
    // 标注类型新增
    baseData = {
      title: "新建标注类型",
      width: 780,
      visible: true,
      isForm: true,
      maskClosable: false,
    }
    modelForm = {
      name: null,
      value: null,
      color: null,
      groupFlag: false,
      childs: [
        {
          name: null,
          value: null,
        }
      ]
    }
  }
  if (type === 1 && modelType === viewMode.EDIT) {
    // 标注类型编辑
    baseData = {
      title: "编辑标注类型",
      width: 780,
      visible: true,
      isForm: true,
      maskClosable: false
    }
    modelForm = {
      name: null,
      value: null,
      color: null,
      groupFlag: true,
      childs: []
    }
  }
  if (type === 2 && modelType === viewMode.VIEW) {
    // 标注组件查看
    baseData = {
      title: "查看标注组件",
      width: 1000,
      visible: true,
      isForm: true,
      maskClosable: false
    }
    modelForm = {}
  }
  if (type === 2 && modelType === viewMode.CREATE) {
    // 标注组件新增
    baseData = {
      title: "新建标注组件",
      width: 1000,
      visible: true,
      isForm: true,
      maskClosable: false
    }
    modelForm = {
      type: "text",
      data: []
    }
  }
  if (type === 2 && modelType === viewMode.EDIT) {
    // 标注组件编辑
    baseData = {
      title: "编辑标注组件",
      width: 1000,
      visible: true,
      isForm: true,
      maskClosable: false
    }
    modelForm = {}
  }
  if (type === 3 && modelType === viewMode.CREATE) {
    // 标注工具新增
    baseData = {
      title: "新建标注工具",
      width: 780,
      visible: true,
      isForm: true,
      maskClosable: false
    }
    modelForm = {}
  }
  if (type === 3 && modelType === viewMode.EDIT) {
    // 标注工具编辑
    baseData = {
      title: "编辑标注工具",
      width: 780,
      visible: true,
      isForm: true,
      maskClosable: false
    }
    modelForm = {
      name: "",
      value: "",
      color: "",
      groupFlag: false,
      child: []
    }
  }
  if (type === 4 && modelType === viewMode.CREATE) {
    // 标签配置新增
    baseData = {
      title: "",
      width: 440,
      visible: true,
      isForm: true,
      maskClosable: false
    }
    modelForm = {}
  }
  if (type === 4 && modelType === viewMode.EDIT) {
    // 标签配置编辑
    baseData = {
      title: "",
      width: 440,
      visible: true,
      isForm: true,
      maskClosable: false,
      isParent: true
    }
    modelForm = {
      name: null,
      value: null
    }
  }
  //新建or编辑标志
  baseData.viewMode = modelType;
  return {
    baseData,
    modelForm
  }
}

type PermissionCodeReturn = {
  searchBtn: string
  addBtn: string
  list: string
  update: string
}

const permCodes = {
  1: {//标注类型
    searchForm: "A040101002",
    addBtn: "A040101003",
    list: "A040101001",
    editBtn: "A040101004"
  },
  2: {//标注组件
    searchForm: "A040201002",
    addBtn: "A040201003",
    list: "A040201001",
    editBtn: "A040201004"
  },
  3: {//标注工具
    searchForm: "A040301002",
    addBtn: "A040301003",
    list: "A040301001",
    editBtn: "A040301004"
  },
  4: {//标注配置
    A: "A040401000",//科室
    'A.list': "A040401001",
    'A.searchForm': "A040401002",
    'A.addBtn': "A040401003",
    'A.editBtn': "A040401004",

    B: "A040402000",//任务标签
    'B.list': "A040402001",
    'B.searchForm': "A040402002",
    'B.addBtn': "A040402003",
    'B.editBtn': "A040402004",

    C: "A040403000",//任务目标
    'C.list': "A040403001",
    'C.searchForm': "A040403002",
    'C.addBtn': "A040403003",
    'C.editBtn': "A040403004",

    D: "A040404000",//任务用途
    'D.list': "A040404001",
    'D.searchForm': "A040404002",
    'D.addBtn': "A040404003",
    'D.editBtn': "A040404004",

    E: "A040405000",//废片原因
    'E.list': "A040405001",
    'E.searchForm': "A040405002",
    'E.addBtn': "A040405003",
    'E.editBtn': "A040405004",

    F: "A040406000",//窗宽窗位
    'F.list': "A040406001",
    'F.searchForm': "A040406002",
    'F.addBtn': "A040406003",
    'F.editBtn': "A040406004",

    G: "A040407000",//算法模型版本
    'G.list': "A040407001",
    'G.searchForm': "A040407002",
    'G.addBtn': "A040407003",
    'G.editBtn': "A040407004",
    },
}
export const getPermCode = (pageType: number, itemType: string): string => {
    return permCodes[pageType][itemType]
}